package cn.kgc.javaweb.dao;

import cn.kgc.javaweb.entity.User;
import cn.kgc.javaweb.util.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;


import java.sql.SQLException;
import java.util.List;

/**
 * @author mosin
 * date 2022/3/15
 * @version 1.0
 */
public class UserDaoImpl  implements UserDao{
    @Override
    public List<User> selectAll() {  //连接数据库  查询数据

        //获取连接
        QueryRunner runner = new QueryRunner(DruidUtil.getDataSource());
        String sql = "select * from user";
        //发送sql 处理结果集
        try {
            List<User> users = runner.query(sql, new BeanListHandler<>(User.class));
            return users;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
